<template>
  <div class="app-container">
    <div class="filter-container">
      <span v-if="authorityHandle(82)" class="filter-title filter-item">身份所属</span>
      <k-select
        v-if="authorityHandle(82)"
        v-model="listQuery.userType"
        class="filter-item right-item"
        style="width:120px"
        :select-params="dict.type.IDENTITY_TYPE"
        @handleSelectEvent="handleFilter"
      />
      <span class="filter-title filter-item">头像框来源</span>
      <k-select
        v-model="listQuery.iconType"
        class="filter-item right-item"
        style="width:120px"
        :select-params="[{ label: '等级', value: 1 }, { label: '活动', value: 2 }]"
        @handleSelectEvent="handleFilter"
      />

      <span class="filter-title filter-item">头像框状态</span>
      <k-select
        v-model="listQuery.useStatus"
        class="filter-item right-item"
        style="width:120px"
        :select-params="[{ label: '使用中', value: 1 }, { label: '未使用', value: 0 }]"
        @handleSelectEvent="handleFilter"
      />

      <span class="filter-title filter-item">获得时间</span>
      <k-date-picker v-model="timeValue" class="filter-item right-item" @hqchang="handleFilter" />
      <k-input
        v-model.trim="listQuery.key"
        class="filter-item"
        is-search
        placeholder="进行搜索"
        :search-fun="handleFilter"
        @keyup.enter.native="handleFilter"
      />
    </div>
    <!--表格相关 -->
    <el-table
      :data="listData"
      border
      fit
      highlight-current-row
      style="width: 100%; border-radius: 8px; margin-top: 30px;"
      :header-cell-style="{ background: '#F6F5FA', color: '#4E4F62' }"
    >
      <el-table-column min-width="60px" type="index" label="序号" align="center" />
      <el-table-column prop="userMobile" min-width="100px" label="用户名" align="center" />
      <el-table-column prop="userType" min-width="100px" label="用户类型" align="center">
        <template slot-scope="scope">
          {{ getUserType(scope.row.userType) }}
        </template>
      </el-table-column>
      <el-table-column prop="iconName" min-width="100px" label="头像框名称" align="center" />
      <el-table-column prop="iconType" min-width="100px" label="头像框来源" align="center">
        <template slot-scope="scope">
          {{ scope.row.iconType === 1 ? '等级' : '活动' }}
        </template>
      </el-table-column>

      <el-table-column prop="iconType" min-width="100px" label="状态" align="center">
        <template slot-scope="scope">
          {{ scope.row.useStatus == 1 ? '使用中' : '未使用' }}
        </template>
      </el-table-column>

      <el-table-column prop="iconRemark" min-width="100px" label="来源明细" align="center" />
      <el-table-column prop="getTime" min-width="100px" label="获得时间" align="center" />
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="loadData"
    />

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { listIconRecordData } from '@/api/avatar'

export default {
  name: 'Extension',
  components: { Pagination },
  dicts: ['IDENTITY_TYPE'],
  data() {
    return {
      timeValue: '',
      listData: [],
      totalRows: 0, // 分页组件--数据总条数
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: '',
          start: ''
        },
        sort: '', // 排序字段 为对应列名,
        direction: '', // 排序 正向(asc)逆向(desc),
        startTime: '', // 最终创建时间",
        endTime: '', // 最早支付时间",
        key: '', // 饰品名称'
        userType: '', // 身份所属',
        iconType: '', // 变更来源',
        useStatus: ''// 头像框状态
      }
    }
  },
  watch: {
    timeValue(val) {
      this.listQuery.startTime = this.timeValue ? this.timeValue[0] : null
      this.listQuery.endTime = this.timeValue ? this.timeValue[1] : null
    }
  },

  created() {
    this.loadData()
  },
  methods: {
    getUserType(userType) {
      let s = ''
      switch (userType) {
        case 1:
          s = '官方'
          break
        case 2:
          s = '主播'
          break
        case 3:
          s = '玩家'
          break
      }
      return s
    },
    loadData() {
      listIconRecordData(this.listQuery).then(res => {
        const data = res.data
        this.listData = data.rows
        this.totalRows = data.totalRows
      })
    },
    // 搜索查询事件
    handleFilter() {
      this.listQuery.pager.pageNo = 1
      this.loadData()
    }
  }
}
</script>

<style lang="scss" scoped>
.filter-container {
  width: 100%;
  height: 48px;
  line-height: 48px;

  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .right-item {
    margin-right: 10px;
  }

  .kInput {
    position: absolute;
    right: 20px;
  }

  .filter-title {
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    font-weight: 500;
    margin-right: 22px;
    color: #14162E;
  }

  .user-item {
    margin-left: 10px;
    margin-right: 20px;
  }

  .user-status,
  .account-status {
    margin-right: 20px;
  }
}
</style>
